<template>
  <div id="body">
    <img class="background" src="../../assets/background.jpg"/>
    <div class="login-form">
      <el-form :label-position="labelPosition" label-width="4rem" :model="form">
        <el-form-item label="用户名">
          <el-input v-model="form.userName"></el-input>
        </el-form-item>
        <el-form-item label="密码">
          <el-input  type="password" v-model="form.password"></el-input>
        </el-form-item>
      </el-form>
      <el-button class="submit-btn" type="primary" :round="true" @click="submit">登录</el-button>
    </div>
  </div>
</template>

<script lang="ts">
import {ILoginModel} from "@/typings";
import {defineComponent, reactive} from "vue";
import {login} from "@/api/system/auth";
import router from "@/router";

export default defineComponent({
  data() {
    return {
      labelPosition: "right",
    };
  },
  setup(props, context) {
    let form: ILoginModel = reactive({userName: "", password: ""});
    const submit = () => {
      login(form).then(res => {
        if (res.tokenValue) {
          window.localStorage.setItem("token", res.tokenValue)
          router.push("/")
        }
      })
    }
    return {form, submit};
  },
});
</script>

<style lang="scss" scoped>
.login-form {
  border-radius: 0.3rem;
  background: rgba(255, 255, 255, 0.7);
  padding: 2rem 3rem 2rem 2rem;
  box-shadow: 0.3rem 0.3rem 2rem rgba(246, 243, 243, 0.7);
  display: flex;
  flex-direction: column;
  align-items: center;
  color: rgba(246, 243, 243, 0.1) !important;

  .submit-btn {
    width: 10rem;
  }
}

#body {
  padding: 0;
  margin: 0;
  width: 100vw;
  height: 100vh;
  display: flex;
  justify-content: center;
  align-items: center;
}

.background {
  z-index: -1;
  width: 100vw;
  height: 100vh;
  position: absolute;
  top: 0;
}
</style>
